﻿using FLAppsApp.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FLAppsApp.ViewModels
{
    public class DeveloperViewModel : ViewModelBase
    {
        string firstName;
        string lastName;

        public string FirstName
        {
            get 
            { 
                return firstName; 
            }
            set 
            {
                if (firstName != value)
                {
                    RaisePropertyChanged("FirstName");
                    firstName = value;
                }
            }
        }

        public string LastName
        {
            get
            {
                return lastName;
            }
            set
            {
                if (lastName != value)
                {
                    lastName = value;
                    RaisePropertyChanged("LastName");
                }
            }
        }

        public List<String> Validate()
        {
            var errors = new List<String>();

            if (String.IsNullOrEmpty(this.FirstName))
                errors.Add("First name is a required field.");

            return errors;
        }


        public async Task Save()
        {
            Developer dev = new Developer();
            dev.FirstName = FirstName;
            dev.LastName = LastName;
            dev.UserId = "abc123";
            dev.Email = "me@me.com";
            await App.DataContext.Developer.InsertAsync(dev);
        }
    }
}
